{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 用来插值，和保存\n",
    "import pandas as pd\n",
    "from scipy import interpolate\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>WATER_TEMPERATURE</th>\n",
       "      <th>PH_VALUE</th>\n",
       "      <th>AMMONIA</th>\n",
       "      <th>DISSOLVED_OXYGEN</th>\n",
       "      <th>PERMANGANATE_INDEX</th>\n",
       "      <th>TOTAL_PHOSPHORUS</th>\n",
       "      <th>TOTAL_NITROGEN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>27.700001</td>\n",
       "      <td>7.68</td>\n",
       "      <td>0.004</td>\n",
       "      <td>2.30</td>\n",
       "      <td>4.00</td>\n",
       "      <td>0.285</td>\n",
       "      <td>6.58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>27.400000</td>\n",
       "      <td>7.63</td>\n",
       "      <td>0.064</td>\n",
       "      <td>1.27</td>\n",
       "      <td>4.23</td>\n",
       "      <td>0.289</td>\n",
       "      <td>7.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>27.400000</td>\n",
       "      <td>7.65</td>\n",
       "      <td>0.061</td>\n",
       "      <td>1.95</td>\n",
       "      <td>4.30</td>\n",
       "      <td>0.303</td>\n",
       "      <td>6.53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>28.200001</td>\n",
       "      <td>7.99</td>\n",
       "      <td>0.008</td>\n",
       "      <td>6.20</td>\n",
       "      <td>4.22</td>\n",
       "      <td>0.294</td>\n",
       "      <td>7.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>28.500000</td>\n",
       "      <td>8.27</td>\n",
       "      <td>0.083</td>\n",
       "      <td>9.33</td>\n",
       "      <td>4.85</td>\n",
       "      <td>0.313</td>\n",
       "      <td>7.07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   WATER_TEMPERATURE  PH_VALUE  AMMONIA  DISSOLVED_OXYGEN  PERMANGANATE_INDEX  \\\n",
       "0          27.700001      7.68    0.004              2.30                4.00   \n",
       "1          27.400000      7.63    0.064              1.27                4.23   \n",
       "2          27.400000      7.65    0.061              1.95                4.30   \n",
       "3          28.200001      7.99    0.008              6.20                4.22   \n",
       "4          28.500000      8.27    0.083              9.33                4.85   \n",
       "\n",
       "   TOTAL_PHOSPHORUS  TOTAL_NITROGEN  \n",
       "0             0.285            6.58  \n",
       "1             0.289            7.33  \n",
       "2             0.303            6.53  \n",
       "3             0.294            7.84  \n",
       "4             0.313            7.07  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('data/masked_water_TOTAL_NITROGEN_data.csv')\n",
    "df.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def interpolate(method):\n",
    "    df = pd.read_csv('data/masked_water_TOTAL_NITROGEN_data.csv')\n",
    "    df = df.where(df != 0, np.nan)\n",
    "    df.interpolate(method=method, inplace=True)\n",
    "    df.to_csv('data/last_interpolate_water_TOTAL_NITROGEN_data.csv', index=False)\n",
    "    \n",
    "interpolate('pad')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:123]",
   "language": "python",
   "name": "conda-env-123-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}